WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
port.h
Go to the documentation of this file.
1// This is not part of WOLF
2// clang-format off
3//
4// Adapted from Ceres Solver 2.2.0 (include/ceres/internal/port.h) so that WOLF autodiff does not
5// require Ceres: namespace 'ceres' renamed to 'wolf::autodiff', and 'CERES_' macros and include
6// guards renamed to 'WOLF_AUTODIFF_'. The original license follows.
7//
8// Ceres Solver - A fast non-linear least squares minimizer
9// Copyright 2023 Google Inc. All rights reserved.
10// http://ceres-solver.org/
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are met:
14//
15// * Redistributions of source code must retain the above copyright notice,
16// this list of conditions and the following disclaimer.
17// * Redistributions in binary form must reproduce the above copyright notice,
18// this list of conditions and the following disclaimer in the documentation
19// and/or other materials provided with the distribution.
20// * Neither the name of Google Inc. nor the names of its contributors may be
21// used to endorse or promote products derived from this software without
22// specific prior written permission.
23//
24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34// POSSIBILITY OF SUCH DAMAGE.
35//
36// Author: keir@google.com (Keir Mierle)
37
38#ifndef WOLF_AUTODIFF_PUBLIC_INTERNAL_PORT_H_
39#define WOLF_AUTODIFF_PUBLIC_INTERNAL_PORT_H_
40
41// A macro to mark a function/variable/class as deprecated.
42// We use compiler specific attributes rather than the c++
43// attribute because they do not mix well with each other.
44#if defined(_MSC_VER)
45#define WOLF_AUTODIFF_DEPRECATED_WITH_MSG(message) __declspec(deprecated(message))
46#elif defined(__GNUC__)
47#define WOLF_AUTODIFF_DEPRECATED_WITH_MSG(message) __attribute__((deprecated(message)))
48#else
49// In the worst case fall back to c++ attribute.
50#define WOLF_AUTODIFF_DEPRECATED_WITH_MSG(message) [[deprecated(message)]]
51#endif
52
53#ifndef WOLF_AUTODIFF_GET_FLAG
54#define WOLF_AUTODIFF_GET_FLAG(X) X
55#endif
56
57// Indicates whether C++20 is currently active
58#ifndef WOLF_AUTODIFF_HAS_CPP20
59#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
60#define WOLF_AUTODIFF_HAS_CPP20
61#endif // __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >=
62 // 202002L)
63#endif // !defined(WOLF_AUTODIFF_HAS_CPP20)
64
65// Prevents symbols from being substituted by the corresponding macro definition
66// under the same name. For instance, min and max are defined as macros on
67// Windows (unless NOMINMAX is defined) which causes compilation errors when
68// defining or referencing symbols under the same name.
69//
70// To be robust in all cases particularly when NOMINMAX cannot be used, use this
71// macro to annotate min/max declarations/definitions. Examples:
72//
73// int max WOLF_AUTODIFF_PREVENT_MACRO_SUBSTITUTION();
74// min WOLF_AUTODIFF_PREVENT_MACRO_SUBSTITUTION(a, b);
75// max WOLF_AUTODIFF_PREVENT_MACRO_SUBSTITUTION(a, b);
76//
77// NOTE: In case the symbols for which the substitution must be prevented are
78// used within another macro, the substitution must be inhibited using parens as
79//
80// (std::numerical_limits<double>::max)()
81//
82// since the helper macro will not work here. Do not use this technique in
83// general case, because it will prevent argument-dependent lookup (ADL).
84//
85#define WOLF_AUTODIFF_PREVENT_MACRO_SUBSTITUTION // Yes, it's empty
86
87// WOLF_AUTODIFF_DISABLE_DEPRECATED_WARNING and WOLF_AUTODIFF_RESTORE_DEPRECATED_WARNING allow
88// to temporarily disable deprecation warnings
89#if defined(_MSC_VER)
90#define WOLF_AUTODIFF_DISABLE_DEPRECATED_WARNING \
91 _Pragma("warning(push)") _Pragma("warning(disable : 4996)")
92#define WOLF_AUTODIFF_RESTORE_DEPRECATED_WARNING _Pragma("warning(pop)")
93#else // defined(_MSC_VER)
94#define WOLF_AUTODIFF_DISABLE_DEPRECATED_WARNING
95#define WOLF_AUTODIFF_RESTORE_DEPRECATED_WARNING
96#endif // defined(_MSC_VER)
97
98#endif // WOLF_AUTODIFF_PUBLIC_INTERNAL_PORT_H_